import axios from 'axios'

// 获取城市定位的函数
export const getCurrentCity = () => {
  // 判断是否又当前城市信息
  const localCity = JSON.parse(localStorage.getItem('hkzf_city'))
  // 没有数据，获取城市并存储
  if (!localCity) {
    return new Promise((resolve, reject) => {
      const curCity = new window.BMapGL.LocalCity()
      curCity.get(async res => {
        // console.log(res)
        try {
          const result = await axios.get(`http://103.153.138.54:8080/area/info?name=${res.name}`)
          localStorage.setItem('hkzf_city', JSON.stringify(result.data.body))
          resolve(result.data.body)
        } catch (e) {
          reject(e)
        }
      })
    })
  }

  return Promise.resolve(localCity)
}

export { API } from './api'

export { BASE_URL } from './url'

export { isAuth } from './auth'